<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>校园百社通登陆界面</title>
    <link rel="stylesheet" type="text/css" href="../.style/Login.css" />
</head>

<body>
    <div id="login">
        <h1>Login</h1>
        <form method="post">
            <input type="text" required="required" placeholder="用户名" name="username" id="id_text"></input>
            <input type="password" required="required" placeholder="密码" name="password" id="id_password"></input>
            <button type="button" class="but" id="log-submit">登录</button>
        </form>
        <p>还没有账号？<a href="Register.html">立即注册</a></p>
    </div>
    <script type="text/javascript" src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.2.1/jquery.min.js"></script>
    <script>
        //AJAX提交登陆数据
        $("#log-submit").click(function () {
            //取到用户填写的登陆数据，向后端发送AJAX请求            
            var username = $("#id_text").val();
            var password = $("#id_password").val();
            var data1 = {
                "username": username,
                "password": password,
            };
            console.log(data1);
            $.ajax({
                url: "http://47.94.228.136:9999/user/login",
                type: "POST",
                contentType: 'application/json',
                dataType: "json",
                data: JSON.stringify(data1),
                success: function (data) {
                    if (data.status) {
                        //有错误就展示错误
                        alert("登陆失败！");
                    } else {
                        //没有错误就跳转到指定页面
                        alert("登陆成功！");
                        console.log(data);
                        console.log(data1);
                    }
                },
                error: function (data) {
                    console.log(data);
                    console.log(data1);
                    alert("出现错误！");
                }
            })

        });
    </script>

</body>


</html>